#!/usr/bin/env bash

help(){
    cat<<__EOF__
Usage: m airdrop [OPTIONS]

Description: Manage AirDrop settings on macOS.

Options:
  --help            Show this help message
  --status          Show AirDrop status
  --enable          Enable airdrop
  --disable         Disable airdrop
__EOF__
    exit 0
}

show_status() {
    local status
    status="$(defaults read com.apple.NetworkBrowser DisableAirDrop 2>/dev/null)"
    if [[ "${status}" == "1" || "${status}" == "true" ]]; then
        echo "AirDrop: disabled"
    else
        echo "AirDrop: enabled"
    fi
}

toggle_airdrop() {
    local state=$1
    defaults write com.apple.NetworkBrowser DisableAirDrop -bool "${state}" && \
        killall -HUP Finder 2>/dev/null
}


case $1 in
    --help)
        help ;;
    --status)
        show_status ;;
    --enable)
        toggle_airdrop NO;;
    --disable)
        toggle_airdrop YES;;
    *)
        help && exit 1 ;;
esac

